/*关闭悬浮窗*/
function closeImgFloat(){
    document.getElementsByClassName("ad3").item(0).setAttribute("style","display: none;")
    x.removeEventListener("mouseover",closeInterval);
    x.removeEventListener("mouseout",startInterval);
    closeInterval();

}
/*图片高度操作参数*/
var a = 1;
/*图片宽度操作参数*/
var b = 1;
/*随机数区间最大值*/
var max = 2;
/*随机数区间最小值*/
var min = 1;
/*页面当前高度*/
var bodyHeight;
/*页面当前宽度*/
var bodyWidth;
/*图片宽高*/
var imgWidth;
var imgHeight;
/*图片初始位置*/
var imgTop;
var imgRight;

var x;

/*悬浮窗摆动逻辑*/
function xunhuan(){

    /*图片所在高度height*/
    var h = parseInt(imgTop);
    /*图片所在宽度width*/
    var w = parseInt(imgRight);
    /*更新位置*/
    imgTop = h + a;
    imgRight = w + b;
    // console.log(imgRight)
    /*改变页面样式*/
    x.setAttribute("style","top:" + imgTop + "px;" + "right:" + imgRight + "px;");


    /*触边反弹，以及重新设置ab速度以此改变角度*/
    if (a < 0 && h <= 0){
        // console.log("a正数")
        a = parseInt(Math.random()*(max-min+1)+min);
    }else if(a > 0 && h >= bodyHeight - parseInt(imgHeight)){
        // console.log("a负数")
        a = parseInt(-(Math.random()*(max-min+1)+min));
    }
    if (b < 0 && w <= 0){
        // console.log("a正数")
        b = parseInt(Math.random()*(max-min+1)+min);
    }else if(b > 0 && w >= bodyWidth - parseInt(imgWidth)){
        // console.log("b负数")
        b = parseInt(-(Math.random()*(max-min+1)+min));
    }

}
/*在外面设定本体，方便绑定事件*/
var timeout = self.setInterval(function () {});
/*启动定时器*/
function startInterval(){
    timeout = self.setInterval("xunhuan()",10)
}
/*关闭定时器*/
function closeInterval(){
    clearInterval(timeout)
}
/*获取页面当前大小*/
function clientBodyWidthAndHeight(){

    bodyHeight =  document.documentElement.clientHeight;
    bodyWidth = document.documentElement.clientWidth;
    imgWidth = window.getComputedStyle(x).width
    imgHeight = window.getComputedStyle(x).height
    console.log('页面大小改变'+"高："+ bodyHeight + "宽：" + bodyWidth)
}
/*开局函数，绑定事件*/
onload=function () {
    // lunbotu()


    x = document.getElementsByClassName("ad3").item(0)
    clientBodyWidthAndHeight();
    startInterval();
    imgTop = window.getComputedStyle(x).top;
    imgRight = window.getComputedStyle(x).right;
    x.addEventListener("mouseover",closeInterval);
    x.addEventListener("mouseout",startInterval);

    // console.log(window.getComputedStyle(x).width)

}
/*页面缩放时动态获取页面大小*/
window.onresize = function () {
    clientBodyWidthAndHeight();
}



